//
// Created by martin on 2/10/22.
//

#ifndef MUDUO_POLLPOLLER_H
#define MUDUO_POLLPOLLER_H

#include "muduo/net/Poller.h"

#include <vector>

struct pollfd;

namespace muduo
{
namespace net
{

/**
 * IO Multiplexing with poll(2).
 */
class PollPoller : public Poller
{
public:
    PollPoller(EventLoop* loop);
    ~PollPoller() override;
    /* 监听函数，调用poll() */
    Timestamp poll(int timeoutMs, ChannelList* activeChannels) override;
    /* ADD/MOD */
    void updateChannel(Channel* channel) override;
    /* DEL */
    void removeChannel(Channel* channel) override;

private:
    /* poll返回后将就绪的fd添加到激活通道中activeChannels */
    void fillActiveChannels(int numEvents,
                            ChannelList* activeChannels) const;
    typedef std::vector<struct pollfd> PollFdList;
    /* poll事件数组，适配poll(2)参数要求 */
    PollFdList pollfds_;
};

}
}



#endif //MUDUO_POLLPOLLER_H
